package com.bankcard.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Pipeline;

public class RedisClient {
    private final JedisPool jedisPool;

    public RedisClient() {
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        this.jedisPool = new JedisPool(poolConfig, "localhost", 6379);
    }

    public String get(String key) {
        try (Jedis jedis = jedisPool.getResource()) {
            return jedis.get(key);
        }
    }

    public void set(String key, String value) {
        try (Jedis jedis = jedisPool.getResource()) {
            jedis.set(key, value);
        }
    }

    public void del(String key) {
        try (Jedis jedis = jedisPool.getResource()) {
            jedis.del(key);
        }
    }

    public Pipeline pipelined() {
        try (Jedis jedis = jedisPool.getResource()) {
            return jedis.pipelined();
        }
    }

    public boolean hexists(String trieKey, String string) {
        try (Jedis jedis = jedisPool.getResource()) {
            return jedis.hexists(trieKey, string);
        }
    }

    // Add other Redis operations as needed
}